package com.cn.cs;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

import static java.lang.Class.forName;
//更新
public class work4 {
        public static void main(String[] args)  {
            try {
                forName("com.mysql.jdbc.Driver");
                Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql1","root","root");
                //获取操作数据库的对象
                PreparedStatement pst =con.prepareStatement("update student set name=?,class=?,age=? where id=?");
                //解析占位符
                pst.setString(1,"张三");
                pst.setString(2,"2103");
                pst.setInt(3,45);
                pst.setString(4,"002");


                //执行sql获取结果
                int count =pst.executeUpdate();
                System.out.println(count>0?"执行成功":"执行失败");
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    }
